package net.lab1024.sa.admin.module.business.project.controller;

import net.lab1024.sa.admin.module.business.oa.enterprise.domain.vo.EnterpriseVO;
import net.lab1024.sa.admin.module.business.project.domain.form.ProjectInfoAddForm;
import net.lab1024.sa.admin.module.business.project.domain.form.ProjectInfoQueryForm;
import net.lab1024.sa.admin.module.business.project.domain.form.ProjectInfoUpdateForm;
import net.lab1024.sa.admin.module.business.project.domain.vo.ProjectInfoVO;
import net.lab1024.sa.admin.module.business.project.service.ProjectInfoService;
import net.lab1024.sa.base.common.code.UserErrorCode;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * 项目表 Controller
 *
 * @Author zzx
 * @Date 2025-08-07 13:47:01
 * @Copyright zzx
 */

@RestController
@Tag(name = "项目表")
public class ProjectInfoController {

    @Resource
    private ProjectInfoService projectInfoService;

    @Operation(summary = "分页查询 @author zzx")
    @PostMapping("/projectInfo/queryPage")
    @SaCheckPermission("projectInfo:query")
    public ResponseDTO<PageResult<ProjectInfoVO>> queryPage(@RequestBody @Valid ProjectInfoQueryForm queryForm) {
        return ResponseDTO.ok(projectInfoService.queryPage(queryForm));
    }

    @Operation(summary = "查询企业详情 @author 开云")
    @GetMapping("/projectInfo/detail/{projectId}")
    @SaCheckPermission("oa:enterprise:detail")
    public ResponseDTO<ProjectInfoVO> getDetail(@PathVariable Long projectId) {
        ProjectInfoVO vo = projectInfoService.getDetail(projectId);
        if (vo == null) {
            return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "数据不存在");
        }
        return ResponseDTO.ok(vo);
    }

    @Operation(summary = "添加 @author zzx")
    @PostMapping("/projectInfo/add")
    @SaCheckPermission("projectInfo:add")
    public ResponseDTO<String> add(@RequestBody @Valid ProjectInfoAddForm addForm) {
        return projectInfoService.add(addForm);
    }

    @Operation(summary = "更新 @author zzx")
    @PostMapping("/projectInfo/update")
    @SaCheckPermission("projectInfo:update")
    public ResponseDTO<String> update(@RequestBody @Valid ProjectInfoUpdateForm updateForm) {
        return projectInfoService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author zzx")
    @PostMapping("/projectInfo/batchDelete")
    @SaCheckPermission("projectInfo:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return projectInfoService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author zzx")
    @GetMapping("/projectInfo/delete/{projectId}")
    @SaCheckPermission("projectInfo:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long projectId) {
        return projectInfoService.delete(projectId);
    }
}
